package cn.iocoder.yudao.framework.common.enums.pay;

import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.enums.metal.MetalTypeEnum;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 钱包业务类型枚举
 */
@Getter
@AllArgsConstructor
public enum PayWalletBizTypeEnum {

    RECHARGE(1, "充值","",0),
    RECHARGE_REFUND(2, "充值退款","",0),
    PAYMENT(3, "钱包支付","",0),
    PAYMENT_REFUND(4, "支付退款","",0),
    RECHARGE_POINT(5, "积分转换","",0),
    WITHDRAW(6, "提现","",0),
    WITHDRAW_CANCEL(7, "取消提现","",0),
    RECHARGE_MATERIAL(8, "板料充值余额","",0),
    UPDATE_BALANCE(9, "管理员修改","",0),

    RECHARGE_GOLD(10, "充值板料（金料）","gold",1),
    RECHARGE_REFUND_GOLD(11, "充值退款板料（金料）", "gold",1),
    PAYMENT_GOLD(12, "板料（金料）支付","gold",1),
    PAYMENT_REFUND_GOLD(13, "板料（金料）支付退款","gold",1),

    RECHARGE_GOLD_BAR(20, "充值板料（金条）","gold_bar",2),
    RECHARGE_REFUND_GOLD_BAR(21, "充值退款板料（金条）","gold_bar",2),
    PAYMENT_GOLD_BAR(22, "板料（金条）支付","gold_bar",2),
    PAYMENT_REFUND_GOLD_BAR(23, "板料（金条）支付退款","gold_bar",2),

    RECHARGE_SILVER(30, "充值板料（白银）","silver",3),
    RECHARGE_REFUND_SILVER(31, "充值退款板料（白银）","silver",3),
    PAYMENT_SILVER(32, "板料（白银）支付","silver",3),
    PAYMENT_REFUND_SILVER(33, "板料（白银）支付退款","silver",3),

    RECHARGE_PLATINUM(40, "充值板料（铂金）","platinum",4),
    RECHARGE_REFUND_PLATINUM(41, "充值退款板料（铂金）","platinum",4),
    PAYMENT_PLATINUM(42, "板料（铂金）支付","platinum",4),
    PAYMENT_REFUND_PLATINUM(43, "板料（铂金）支付退款","platinum",4),

    RECHARGE_PALLADIUM(50, "充值板料（钯金）","palladium",5),
    RECHARGE_REFUND_PALLADIUM(51, "充值退款板料（钯金）","palladium",5),
    PAYMENT_PALLADIUM(52, "板料（钯金）支付","palladium",5),
    PAYMENT_REFUND_PALLADIUM(53, "板料（钯金）支付退款","palladium",5),
    ;


    /**
     * 业务类型
     */
    private final Integer type;
    /**
     * 业务名称
     */
    private final String name;
    private final String desc;
    private final Integer walletType;

    public static PayWalletBizTypeEnum getEnum(Integer type) {
        if (type == null) {
            return null;
        }
        return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
    }
    public static PayWalletBizTypeEnum getPayEnumByWallet(Integer type) {
        if (type == null) {
            return null;
        }
        switch (type) {
            case 0 -> {
                return PAYMENT;
            }
            case 1 -> {
                return PAYMENT_GOLD;
            }
            case 2 -> {
                return PAYMENT_GOLD_BAR;
            }
            case 3 -> {
                return PAYMENT_SILVER;
            }
            case 4 -> {
                return PAYMENT_PLATINUM;
            }
            case 5 -> {
                return PAYMENT_PALLADIUM;
            }
        }
        return null;
    }

    public static boolean isRecharge(PayWalletBizTypeEnum bizType) {
        return ObjectUtils.equalsAny(bizType, RECHARGE,RECHARGE_MATERIAL,RECHARGE_GOLD, RECHARGE_GOLD_BAR, RECHARGE_SILVER,
                RECHARGE_PALLADIUM, RECHARGE_PLATINUM);
    }

    public static boolean isPayment(PayWalletBizTypeEnum bizType) {
        return ObjectUtils.equalsAny(bizType, PAYMENT,PAYMENT_GOLD, PAYMENT_GOLD_BAR, PAYMENT_SILVER,
                PAYMENT_PALLADIUM, PAYMENT_PLATINUM);
    }

    public static boolean isRechargeRefund(PayWalletBizTypeEnum bizType) {
        return ObjectUtils.equalsAny(bizType, RECHARGE_REFUND,RECHARGE_REFUND_GOLD, RECHARGE_REFUND_GOLD_BAR,
                RECHARGE_REFUND_SILVER, RECHARGE_REFUND_PALLADIUM, RECHARGE_REFUND_PLATINUM);
    }

    public static Integer getReChargeByMetal(MetalTypeEnum metalType) {
        if (metalType == null) {
            return null;
        }
        return switch (metalType) {
            case GOLD -> RECHARGE_GOLD.getType();
            case GOLD_BAR -> RECHARGE_GOLD_BAR.getType();
            case SILVER -> RECHARGE_SILVER.getType();
            case PLATINUM -> RECHARGE_PLATINUM.getType();
            case PALLADIUM -> RECHARGE_PALLADIUM.getType();
            default -> RECHARGE.getType();
        };
    }

    public static boolean isWithDraw(PayWalletBizTypeEnum bizType) {
        return ObjectUtils.equalsAny(bizType, WITHDRAW);
    }
}